<template>
  <div class="red-card">
    <transition
      name="turn"
      mode="out-in"
    >
      <div
        class="front"
        @click="luckyTime"
        v-if="!truning"
        key="back"
      >
        <span>{{index+1}}</span>
      </div>
      <div
        v-if="truning"
        class="back"
        key="front"
      >{{'￥'+money}}</div>
    </transition>
  </div>
</template>

<script>
export default {
  props: {
    money: {
      type: Number
    },
    index: {
      type: Number
    }
  },
  data () {
    return {
      truning: false
    }
  },
  methods: {
    luckyTime () {
      this.truning = true
      const noticeAudio = require('@/assets/开红包音效.mp3')
      const audio = new Audio(noticeAudio)
      audio.play() // 播放
      // eslint-disable-next-line no-undef
      OpenMouseEffects()
      document.getElementById('test').removeAttribute('class')
      setTimeout(() => {
        // eslint-disable-next-line no-undef
        CloseMouseEffects()
        document.getElementById('test').setAttribute('class', 'no-event')
      }, 1500)
    }
  }
}
</script>

<style lang="scss">
.red-card {
  cursor: pointer;
  width: 150px;
  height: 300px;
  border-radius: 5px;
  margin-right: 100px;
  position: relative;
  .front {
    width: 150px;
    height: 250px;
    background-image: url("../assets/红包.jpg");
    background-position: center 0;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    top: 0;
    left: 0;
    z-index: 2;
    color: #faf408;
    font-family: auto;
    font-size: 80px;
    font-weight: 700;
  }
  .back {
    position: absolute;
    top: 0;
    left: 0;
    width: 150px;
    height: 250px;
    background-image: url("../assets/红包开.jpg");
    background-position: center 0;
    background-repeat: no-repeat;
    background-size: 100% auto;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #faf408;
    font-family: auto;
    font-size: 40px;
    font-weight: 700;
  }
  &:last-child {
    margin-right: 0;
  }
}

.turn-leave-active {
  // transition: opacity .5s;
  animation: rotate 0.5s;
}
.turn-enter-active {
  animation: rotate 0.5s reverse;
}

@keyframes rotate {
  0% {
    transform: rotateY(0);
  }
  50% {
    transform: rotateY(90deg);
  }
  100% {
    transform: rotateY(180deg);
  }
}
</style>
